package com.ssm.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.pojo.cart.AddCart;
import com.ssm.pojo.cart.AddCartResult;
import com.ssm.pojo.cart.CartList;
import com.ssm.pojo.cart.RemoveAllCartResult;
import com.ssm.pojo.cart.RemoveCart;
import com.ssm.pojo.cart.RemoveCartResult;
import com.ssm.pojo.cart.UpdateCart;
import com.ssm.pojo.cart.UpdateCartResult;
import com.ssm.service.CartService;
 

@Controller
public class CartController {
	  @Autowired
	  CartService cartService;
	  
	  // 获取购物车商品列表 API
	  @RequestMapping(value="/api/v1/cart",method = RequestMethod.POST)
	  @ResponseBody
	  public CartList list(int userId) {
		 return cartService.list(userId);
	  }
	  
	  // 移除购物车子项 API
	  @RequestMapping(value="/api/v1/cart/items/remove",method = RequestMethod.POST)
	  @ResponseBody
	  public RemoveCartResult remove(RemoveCart removeCart) {
		 return cartService.delete(removeCart);
	  }
	  
	  // 清空全部购物车 API
	  @RequestMapping(value="/api/v1/cart/items/removeall",method = RequestMethod.POST)
	  @ResponseBody
	  public RemoveAllCartResult removeAll(int userId) {
		 return cartService.deleteAll(userId);
	  }
	  
	  // 新增购物车 API
	  @RequestMapping(value="/api/v1/cart/add",method = RequestMethod.POST)
	  @ResponseBody
	  public AddCartResult add(AddCart addCart) {
		 return cartService.add(addCart);
	  }
	  
	  // 更新购物车 API
	  @RequestMapping(value="/api/v1/cart/items/update",method = RequestMethod.POST)
	  @ResponseBody
	  public UpdateCartResult update(UpdateCart updateCart) {
		 return cartService.update(updateCart);
	  } 

	 
	  
}